home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Games / JST / sources / OSEmu / graphics.s < prev    next >
Encoding:
Text File  |  2001-03-19  |  39.1 KB  |  1,998 lines

  1. * $Id: graphics.s 1.1 1999/02/03 04:10:07 jotd Exp jotd $
  2. **************************************************************************
  3. *    GRAPHICS LIBRARY
  4. **************************************************************************
  5.  
  6. CMOVE:MACRO
  7.     move.l    \1,A1
  8.     move.w    \2,D0
  9.     move.w    \3,D1
  10.     bsr    _CMove
  11.     bsr    _CBump
  12.     ENDM
  13.  
  14. CEND:MACRO
  15.     move.l    \1,A1
  16.     move.w    #10000,D0
  17.     move.w    #255,D1
  18.     bsr    _CWait
  19.     bsr    _CBump
  20.     ENDM
  21.  
  22. **************************************************************************
  23. *    INITIALIZATION
  24. **************************************************************************
  25.  
  26. GFXINIT        move.l    _gfxbase,d0
  27.         beq    .init
  28.         rts
  29.  
  30. .init        move.l    #1056,d0    ;-_LVOWriteChunkyPixels,d0
  31.         move.l    #$2A8,d1
  32.         lea    _gfxname,a0
  33.         bsr    _InitLibrary
  34.         move.l    d0,a0
  35.         move.l    d0,_gfxbase
  36.         
  37.         patch    _LVOOwnBlitter(a0),MYRTS
  38.         patch    _LVODisownBlitter(a0),MYRTS
  39.         patch    _LVOInitView(a0),_InitView
  40.         patch    _LVOInitVPort(a0),_InitVPort
  41.         patch    _LVOFreeVPortCopLists(a0),_FreeVPortCopLists
  42.         patch    _LVOInitBitMap(a0),_InitBitMap
  43.         patch    _LVOInitRastPort(a0),_InitRastPort
  44.         patch    _LVOMakeVPort(a0),_MakeVPort
  45.         patch    _LVOMrgCop(a0),_MrgCop
  46.         patch    _LVOCWait(a0),_CWait    ; added by JOTD
  47.         patch    _LVOCMove(a0),_CMove    ; added by JOTD
  48.         patch    _LVOCBump(a0),_CBump    ; added by JOTD
  49.         patch    _LVOTextLength(a0),_TextLength    ; added by JOTD, lame
  50.         patch    _LVOLoadView(a0),_LoadView
  51.         patch    _LVOLoadRGB4(a0),_LoadRGB4
  52. ;;        patch    _LVOLoadRGB32(a0),_LoadRGB32
  53.         patch    _LVOSetRGB4(a0),_SetRGB4
  54.         patch    _LVOGetRGB4(a0),_GetRGB4
  55.         patch    _LVOFreeSprite(a0),_FreeSprite
  56.         patch    _LVOGetSprite(a0),_GetSprite
  57.         patch    _LVOChangeSprite(a0),_ChangeSprite
  58.         patch    _LVOMoveSprite(a0),_MoveSprite
  59.         patch    _LVOWaitBlit(a0),_WaitBlit
  60.         patch    _LVOBltBitMap(a0),_BltBitMap
  61.         patch    _LVOClipBlit(a0),_ClipBlit        ; not accurate!
  62.         patch    _LVOVBeamPos(a0),_VBeamPos
  63.         patch    _LVODraw(a0),_Draw
  64.         patch    _LVOAllocBitMap(a0),_AllocBitMap    ; V39, Ripped by JOTD
  65.         patch    _LVOMove(a0),_Move
  66.         patch    _LVOSetAPen(a0),_SetAPen
  67.         patch    _LVOSetBPen(a0),_SetBPen
  68.         patch    _LVOSetDrMd(a0),_SETDRAWMODE
  69.         patch    _LVOWaitTOF(a0),_WaitTOF
  70.         patch    _LVOWaitBOVP(a0),_WaitBOVP        ; -- added by JOTD
  71.         patch    _LVORectFill(a0),_RectFill        ; -- added by JOTD
  72.         patch    _LVOSetRast(a0),_SetRast        ; -- added by JOTD
  73.         patch    _LVOInitTmpRas(a0),_InitTmpRas    ; -- added by JOTD
  74.         patch    _LVOInitArea(a0),_InitArea        ; -- added by JOTD
  75.         patch    _LVOReadPixel(a0),_ReadPixel
  76.         patch    _LVOWritePixel(a0),_WritePixel
  77.         patch    _LVOBltTemplate(a0),_BltTemplate
  78.         patch    _LVOAllocRaster(A0),_ALLOCRASTER
  79.         patch    _LVOFreeRaster(A0),_FREERASTER
  80.         patch    _LVOFreeCprList(A0),_FreeCprList ; JOTD, burntime
  81.         patch    _LVOBltClear(A0),_BltClear
  82.         patch    _LVOGetColorMap(A0),_GETCOLORMAP
  83.         patch    _LVOFreeColorMap(A0),_FREECOLORMAP
  84.         patch    _LVOUCopperListInit(a0),_UCopperListInit ; -- added by JOTD
  85.         patch    _LVOBestModeIDA(A0),MYRTZ    ; -- added by JOTD
  86.         patch    _LVOBltMaskBitMapRastPort(A0),_BLTMASKBITMAPRASTPORT    ; Harry
  87.         patch    _LVOOpenFont(A0),_OPENFONT
  88.         patch    _LVOSetFont(A0),_SETFONT
  89.         patch    _LVOText(A0),_PRINTTEXT
  90.         patch    _LVOGetDisplayInfoData(A0),MYRTZ    ; JOTD, DGeneration
  91.         MOVE.L    #MYVIEW,gb_ActiView(A0)
  92.         lea    STDCOPPER(PC),a1
  93.         MOVE.L    a1,(gb_LOFlist,A0)
  94.         MOVE.L    a1,(gb_SHFlist,A0)
  95.         MOVE.L    a1,(_custom+cop2lc)
  96.  
  97.         move.l    a1,OSM_COPLIST2            ; added by JOTD
  98.  
  99.         lea    CPJMP2,a1
  100.         move.l    a1,(gb_copinit,a0)
  101.  
  102.         MOVE.L    a1,(_custom+cop1lc)
  103.         move.l    a1,OSM_COPLIST1            ; added by JOTD
  104.         lea.l   _TOPAZ8FONT(PC),a1        ; added by Harry
  105.         move.l  a1,(gb_DefaultFont,a0)        ; added by Harry
  106.  
  107.         moveq    #4,d0                ;pal
  108.         cmp.l    #PAL_MONITOR_ID,_monitor
  109.         beq.b    .1
  110.         moveq    #1,d0                ;ntsc
  111. .1        MOVE.W    d0,(gb_DisplayFlags,A0)
  112.  
  113.         clr.b    (gb_SpriteReserved,a0)
  114.         move.b    #3,($ED,A0)        ;jeff, crb_reserved, ripped!
  115.  
  116.         move.l    A1,-(A7)
  117.         lea    .gfx1A8_table(pc),A1
  118.         move.l    (A1)+,($1A8,A0)
  119.         move.l    (A1)+,($1AC,A0)
  120.         move.l    (A1)+,($1B0,A0)
  121.         move.l    (A1)+,($1B4,A0)
  122.         move.l    (A1)+,($1B8,A0)
  123.         
  124.         move.l    (A7)+,A1
  125.  
  126.         move.l    A6,-(A7)
  127.         move.l    $4.W,A6
  128.         move.l    A0,($9C,A6)    ; Jeff: change intvec data to GfxBase (Banshee...)
  129.         move.l    (A7)+,A6
  130.  
  131.         move.l    $4.W,(gb_ExecBase,A0)    ; sets ExecBase to gb_ExecBase offset
  132.  
  133.         move.l    #_TOPAZ8FONT,(gb_DefaultFont,A0)  ; bugfix, A0 missing!
  134.  
  135.         ; sprites initialization (JOTD)
  136.         move.l    A6,-(A7)
  137.         move.l    A0,A6        ; sets GfxBase
  138.         bsr    init_sprites
  139.         move.l    (A7)+,A6
  140.  
  141.         move.l    A1,-(A7)
  142.         lea    _MonitorSpec(pc),A1
  143.         move.l    A1,(gb_current_monitor,A0)
  144.         move.l    (A7)+,A1
  145.  
  146.         clr.l    -(a7)                ;TAG_DONE
  147.         pea    RESTORECOPPER2(pc)
  148.         move.l    #WHDLTAG_CBSWITCH_SET,-(a7)
  149.         move.l    a7,a0
  150.         move.l    _RESLOAD(pc),a1
  151.         jsr    (resload_Control,a1)
  152.         lea    (12,a7),a7                      ;restore sp
  153.         
  154.         tst.w    (_custom+copjmp1)
  155.         move.w    #DMAF_SETCLR!DMAF_MASTER!DMAF_COPPER!DMAF_BLITTER,(_custom+dmacon)
  156.  
  157.         rts
  158.  
  159.  
  160. ; ??? used for AllocBitMap
  161. .gfx1A8_table:
  162.     dc.l    abm_table
  163.     dc.l    abm_table+120
  164.     dc.l    abm_table+144
  165.     dc.l    abm_table+168
  166.     dc.l    abm_table+192
  167.  
  168.     ; initialize sprites to avoid graphics glitches because of
  169.     ; wild sprite pointers
  170.  
  171. init_sprites:
  172.     movem.l    D0-D2/A0-A1,-(A7)
  173.     moveq.l    #7,D2        ; 8 sprites to set
  174.  
  175.     lea    .cursor_sprite_data(pc),A2
  176. .loop:
  177.     lea    .cursor_sprite_struct(pc),A1
  178.     move.w    D2,.sprnum
  179.     sub.l    A0,A0    ; no view port!
  180.     JSRLIB    ChangeSprite
  181.     dbf    D2,.loop
  182.     movem.l    (A7)+,D0-D2/A0-A1
  183.     rts
  184.  
  185. .cursor_sprite_data:
  186.     dc.W    0,0
  187.     dc.w    $AAAA,$5555
  188.     dc.W    0,0
  189. .cursor_sprite_struct:
  190.     dc.l    0
  191.     dc.w    1    ; height=1
  192.     dc.w    0,0    ; X,Y
  193. .sprnum
  194.     dc.w    0    ; sprite number
  195.     
  196. _MonitorSpec
  197.     blk.b    $28,$EE
  198.     dc.w    $20
  199.     blk.b    $9C-$2A,$EE
  200.  
  201. RESTORECOPPER2    move.l    a1,-(A7)
  202.         move.l    _gfxbase,a1
  203.         move.l    (gb_LOFlist,a1),a1
  204.         move.l    a1,(_custom+cop2lc)
  205.         move.l    a1,OSM_COPLIST2
  206.         move.l    (A7)+,a1
  207.         jmp    (A0)
  208.  
  209.     CNOP 0,4
  210. CPJMP2
  211.         dc.l    $0201fffe    ;wait 0,2
  212.         DC.L    $008A0000    ;copjmp2
  213. STDCOPPER
  214.         DC.L    $FFFFFFFE
  215.  
  216. MYVIEW
  217.     DC.L    _INITVIEWPORT
  218.     DC.L    STDCOPPER
  219.     DC.L    STDCOPPER
  220.     DC.W    0
  221.     DC.W    0
  222.     DC.W    0
  223.  
  224. _INITVIEWPORT
  225.     DC.L    $EEEEEEEE
  226.     DC.L    $EEEEEEEE
  227.     DC.L    $EEEEEEEE
  228.     DC.L    $EEEEEEEE
  229.     DC.L    $EEEEEEEE
  230.     DC.L    0        ; UCopIns
  231.     DC.W    0
  232.     DC.W    0
  233.     DC.W    0
  234.     DC.W    0
  235.     DC.W    0
  236.     DC.B    0,0
  237.     DC.L    _INITRASINFO
  238.  
  239. _INITLAYER:
  240.     dc.l    _INITLAYER,_INITLAYER
  241.     dc.l    0
  242.     dc.l    $BBBBEEEE    ; rastport
  243.     ds.b    160-16
  244.  
  245. _INITRASINFO
  246.     DC.L    0
  247.     DC.L    $EEEEEEEE
  248.     DC.W    0
  249.     DC.W    0
  250.  
  251. _FONTTABLE
  252.     DC.L    _TOPAZNAME,_TOPAZ8FONT
  253.     DC.L    0
  254.  
  255. _TOPAZNAME
  256.     DC.B    'topaz.font',0
  257.     EVEN
  258.  
  259. _TOPAZ8FONT
  260.     DC.L    0,0,0,0,0        ;EMPTY MESSAGEPORT
  261.     DC.W    8            ;YSIZE
  262.     DC.B    0            ;NO SPECIAL STYLE
  263.     DC.B    $41            ;FONTFLAGS:DESIGNED,ROMFONT
  264.     DC.W    8            ;XSIZE
  265.     DC.W    6            ;BASELINE
  266.     DC.W    1            ;FETT: 1 PIXEL VERSETZT
  267.     DC.W    1            ;1 TASK BENUTZT FONT (DUMMY)
  268.     DC.B    $20            ;LOWEST CHAR IS SPACE
  269.     DC.B    $FF            ;HIGHEST CHAR IS "y
  270.     DC.L    _TOPAZ8DATA        ;FONTIMAGES
  271.     DC.W    $C0            ;MODULO
  272.     DC.L    _TOPAZ8OFFSETS        ;OFFSETTABLES
  273.     DC.L    0            ;NON PROPORTIONAL FONT
  274.     DC.L    0            ;NO KERNING
  275.  
  276. _TOPAZ8DATA
  277.     INCBIN    REPLFONT_DATA
  278.  
  279. _TOPAZ8OFFSETS
  280.     INCBIN    REPLFONT_BITS
  281.  
  282. **************************************************************************
  283. *    GRAPHICS LIBRARY FUNCTIONS
  284. **************************************************************************
  285.  
  286. _UCopperListInit:
  287.     cmp.l    #0,a0
  288.     bne.b    .nz
  289.     moveq.l    #0,D0
  290.     bra.b    .exit    ; error, returns NULL
  291. .nz
  292.  
  293.     movem.l    D1-A6,-(A7)
  294.  
  295.     clr.l    (A0)    ; next list
  296.     
  297.     move.l    A0,A2
  298.     move.l    D0,D2    ; number of copper instructions needed
  299.  
  300.     move.l    #$22,D0        ; size of coplist struct
  301.     move.l    #MEMF_CLEAR,D1
  302.     move.l    (gb_ExecBase,A6),A6    ; gfxbase
  303.     JSRLIB    AllocMem
  304.     move.l    D0,(ucl_FirstCopList,A2)
  305.     beq.b    .alloc_fail
  306.  
  307.     move.l    D0,(ucl_CopList,A2)    ; coplist pointer stored in UCopList struct
  308.  
  309.     move.l    D0,A3        ; coplist pointer
  310.  
  311.     ; init some fields
  312.  
  313.     clr.l    (A3)
  314.     move.l    #$BEBEBEBE,(cl__CopList,A3)
  315.     clr.l    (cl__ViewPort,A3)
  316.     clr.l    (cl_CopLStart,A3)
  317.     move.l    #$BEBEBEBE,(cl_CopSStart,A3)
  318.     clr.w    (cl_Count,A3)
  319.     move.w    D2,(cl_MaxCount,A3)
  320.  
  321.     move.l    D2,D0        ; # of instructions
  322.     mulu    #6,D0        ; size of coplist struct
  323.     move.l    #MEMF_CLEAR,D1
  324.     JSRLIB    AllocMem
  325.     move.l    D0,(cl_CopIns,A3)    ; save list of copper instructions
  326.     move.l    D0,(cl_CopPtr,A3)    ; pointer on current copper instruction
  327.     beq.b    .alloc_fail
  328.  
  329.  
  330.     movem.l    (A7)+,D1-A6
  331.     move.l    (ucl_FirstCopList,A0),D0    ; return value
  332. .exit:
  333.     rts
  334.  
  335. .alloc_fail:
  336.     GFXFAIL    _LVOUCopperListInit
  337.  
  338.  
  339. ; does not affect registers!
  340.  
  341. _CMove:
  342.     movem.l    A0/A2,-(A7)
  343.     move.l    (ucl_FirstCopList,A1),A0
  344.     move.l    (cl_CopPtr,A0),A2        ; gets current copper instruction
  345.     move.w    #0,(0,A2)            ; MOVE instruction
  346.     move.w    D0,(2,A2)
  347.     move.w    D1,(4,A2)
  348.     movem.l    (A7)+,A0/A2
  349.     rts
  350.  
  351. ; < A1: UCopList
  352. ; < D0: horiz wait
  353. ; < D1: vert. wait
  354. ; does not affect registers!
  355.  
  356. _CWait:
  357.     movem.l    A0/A2,-(A7)
  358.     move.l    (ucl_FirstCopList,A1),A0
  359.     move.l    (cl_CopPtr,A0),A2        ; gets current copper instruction
  360.     move.w    #1,(0,A2)            ; WAIT instruction
  361.     move.w    D0,(2,A2)
  362.     move.w    D1,(4,A2)
  363.     movem.l    (A7)+,A0/A2
  364.     rts
  365.  
  366. ; < A1: UCopList
  367. ; A0 is preserved here for convenience reasons (MakeVPort) !!!
  368.  
  369. _CBump:
  370.     move.l    A0,-(a7)
  371.     move.l    (ucl_FirstCopList,A1),A0
  372.     addq.l    #6,(cl_CopPtr,A0)        ; next copper instruction
  373.     addq.w    #1,(cl_Count,A0)
  374.     move.l    (a7)+,A0
  375.     rts
  376.  
  377. ; < A0: viewport
  378.  
  379. _FreeVPortCopLists:
  380.     movem.l    A2/A6,-(A7)
  381.     move.l    A0,A2
  382.  
  383.     ; JOTD: free copper list structure and contents
  384.  
  385.     move.l    (vp_DspIns,a2),A0
  386.     move.l    (cl_CopIns,A0),A1    ; copper instructions
  387.     move.l    (cl_MaxCount,A0),D0
  388.     mulu    #6,D0            ; size of buffer
  389.     move.l    $4.W,A6
  390.     JSRLIB    FreeMem
  391.  
  392.     move.l    (vp_DspIns,a2),A1
  393.     move.l    (cl_CopLStart,a1),D0
  394.     beq.b    .nomerged
  395.     move.l    D0,A1
  396.     move.l    $4.W,A6
  397.     JSRLIB    FreeVec
  398. .nomerged
  399.     move.l    (vp_DspIns,a2),A1
  400.     cmp.l    #0,A1
  401.     beq.b    .nodsp
  402.     move.l    #$22,D0
  403.     JSRLIB    FreeMem
  404.  
  405.     clr.l    (vp_DspIns,a2)
  406. .nodsp:
  407.  
  408.     ; nothing allocated for the 2 of them below
  409.  
  410.     clr.l    (vp_SprIns,a2)
  411.     clr.l    (vp_ClrIns,a2)
  412.  
  413.     move.l    (vp_UCopIns,a2),D0
  414.     beq.b    .skip
  415.     clr.l    (vp_UCopIns,a2)
  416.  
  417.     ; JOTD, now that UCopListInit is made, got to free the struct
  418.     ; first, free copper instructions
  419.  
  420.     move.l    D0,A0
  421.     move.l    (ucl_FirstCopList,A0),A2
  422.     move.l    (cl_CopIns,A2),A1    ; copper instructions
  423.     move.l    (cl_MaxCount,A2),D0
  424.     mulu    #6,D0            ; size of buffer
  425.     move.l    $4.W,A6
  426.     JSRLIB    FreeMem
  427.  
  428.     ; frees copperlist structure
  429.  
  430.     move.l    A2,A1
  431.     move.l    #$22,D0
  432.     move.l    $4.W,A6
  433.     JSRLIB    FreeMem
  434. .skip
  435.  
  436.     movem.l    (a7)+,A2/A6
  437.     rts
  438.  
  439. _InitTmpRas:
  440.     move.l    A1,(A0)
  441.     move.l    D0,4(A0)
  442.     move.l    A0,D0
  443.     rts
  444.  
  445. _InitArea:
  446.     MOVE.L    A1,4(A0)
  447.     MOVE.L    A1,(A0)
  448.     MOVE    D0,18(A0)
  449.     ASL.L    #2,D0
  450.     ADDA    D0,A1
  451.     MOVE.L    A1,12(A0)
  452.     MOVE.L    A1,8(A0)
  453.     CLR    16(A0)
  454.     RTS
  455.     
  456. _InitView
  457.     movem.l    D0/A1,-(A7)
  458.     move.w    #$8,D0
  459. .zero
  460.     clr.w    (A1)+
  461.     dbf    D0,.zero
  462.     movem.l    (A7)+,D0/A1
  463.     rts
  464.  
  465. _InitVPort    
  466.     movem.l    D0/A0,-(A7)
  467.     move.w    #9,D0
  468. .zero
  469.     clr.l    (A0)+
  470.     dbf    D0,.zero
  471.  
  472.     movem.l    (A7)+,D0/A0    
  473.     move.b #$24,(vp_SpritePriorities,A0)
  474.     rts
  475.  
  476. ; < A1: rastport (ignored)
  477. ; < A0: text pointer (ignored)
  478. ; < D0: string length
  479.  
  480. _TextLength:
  481.     ; * 8 should do the trick
  482.     add.l    D0,D0
  483.     add.l    D0,D0
  484.     add.l    D0,D0
  485.     rts
  486.  
  487. ; < A1: rastport structure
  488.  
  489. _InitRastPort
  490.     MOVE.L    #_INITLAYER,(A1)        ; JOTD: Maniac Mansion
  491.     MOVE.L    #0,rp_BitMap(A1)
  492.  
  493.     MOVE.L    #$EEEEEEEE,rp_AreaPtrn(A1)
  494.  
  495.     MOVE.L    #$EEEEEEEE,rp_TmpRas(A1)
  496.     MOVE.L    #$EEEEEEEE,rp_AreaInfo(A1)
  497.     MOVE.L    #0,rp_GelsInfo(A1)
  498.     MOVE.L    #$FF0000FF,rp_Mask(A1)    
  499.     MOVE.L    #$01000000,rp_DrawMode(A1)
  500.     CLR.L    rp_Flags(A1)
  501.     CLR.L    rp_cp_x(A1)
  502.     CLR.L    rp_minterms(A1)
  503.     CLR.L    rp_minterms+4(A1)
  504.     CLR.L    rp_PenWidth(A1)
  505.     MOVE.L    #_TOPAZ8FONT,rp_Font(A1)
  506.     CLR.W    rp_AlgoStyle(A1)
  507.     MOVE.L    #$00080008,rp_TxHeight(A1)
  508.     MOVE.L    #$00060008,rp_TxBaseline(A1)
  509.     CLR.L    rp_RP_User(A1)
  510.  
  511.     ; added by JOTD (Test Drive II)
  512.     MOVE.B    #1,rp_FgPen(A1)
  513.     MOVE.B    #2,rp_BgPen(A1)
  514.     RTS
  515.  
  516. .area_ptrn:
  517.     dc.w    0
  518.  
  519. _SetAPen:
  520.     MOVE.B    D0,rp_FgPen(A1)
  521.     RTS
  522.  
  523. _SetBPen:
  524.     MOVE.B    D0,rp_BgPen(A1)
  525.     RTS
  526.  
  527. _SETDRAWMODE
  528.     MOVE.B    D0,rp_DrawMode(A1)
  529.     RTS
  530.  
  531. _Move:
  532.     MOVE.W    D0,rp_cp_x(A1)
  533.     MOVE.W    D1,rp_cp_y(A1)
  534.     RTS
  535.  
  536. _BltClear:
  537.     AND.W    #2,D1
  538.     BNE.S    .FAIL
  539.     LSR.W    #1,D0
  540.     SUBQ.W    #1,D0
  541. .1    CLR.W    (A1)+
  542.     DBF    D0,.1
  543.     RTS
  544.  
  545. .FAIL        pea    _LVOBltClear
  546.         pea    _gfxname
  547.         bra    _emufail
  548.  
  549. _ALLOCRASTER
  550.     ADD.W    #$F,D0
  551.     LSR.W    #3,D0
  552.     AND.W    #$FFFE,D0
  553.     MULU    D1,D0
  554.     MOVEQ.L    #MEMF_CHIP!MEMF_PUBLIC,D1
  555.     bsr    ForeignAllocMem
  556.     RTS
  557.  
  558. _FREERASTER
  559.     ADD.W    #$F,D0
  560.     LSR.W    #3,D0
  561.     AND.W    #$FFFE,D0
  562.     MULU    D1,D0
  563.     MOVE.L    A0,A1
  564.     bsr    ForeignFreeMem
  565.     RTS
  566.  
  567. ; < D0: entries #
  568. ; > D0: colormap pointer
  569.  
  570. _GETCOLORMAP
  571.     MOVE.L    D0,-(A7)
  572.     ADD.L    D0,D0
  573.     ADDQ.L    #8,D0
  574.     MOVE.L    #MEMF_CLEAR,D1
  575.     bsr    ForeignAllocMem
  576.     TST.L    D0
  577.     BEQ.S    .FAIL
  578.     MOVE.L    D0,A0
  579.     MOVE.L    (A7)+,D1
  580.     MOVE.W    D1,cm_Count(A0)
  581.     LEA.L    8(A0),A1
  582.     MOVE.L    A1,cm_ColorTable(A0)
  583.     CMP.W    #$20,D1
  584.     BLS.S    .1
  585.     MOVEQ.L    #$20,D1
  586. .1    LEA.L    .COLORTAB(PC),A0
  587. .2    MOVE.W    (A0)+,(A1)+
  588.     SUBQ.W    #1,D1
  589.     BNE.S    .2
  590.  
  591. .FAIL    RTS
  592.  
  593. .COLORTAB
  594.     DC.B    $00,$00,$0F,$00,$00,$F0,$0F,$F0
  595.     DC.B    $00,$0F,$0F,$0F,$00,$FF,$0F,$FF
  596.     DC.B    $06,$20,$0E,$50,$09,$F1,$0E,$B0
  597.     DC.B    $05,$5F,$09,$2F,$00,$F8,$0C,$CC
  598.     DC.B    $00,$00,$01,$11,$02,$22,$03,$33
  599.     DC.B    $04,$44,$05,$55,$06,$66,$07,$77
  600.     DC.B    $08,$88,$09,$99,$0A,$AA,$0B,$BB
  601.     DC.B    $0C,$CC,$0D,$DD,$0E,$EE,$0F,$FF
  602.  
  603. _FREECOLORMAP    ;A0-*COLORMAP
  604.     MOVE.L    (A2),-(A7)
  605.     MOVE.L    A0,A2
  606.     MOVE.L    cm_ColorTable(A2),A1
  607.     MOVEQ.L    #0,D0
  608.     MOVE.W    cm_Count(A2),D0
  609.     ADD.L    D0,D0
  610.     ADDQ.L    #7,D0
  611.     AND.L    #$FFFFFFF8,D0
  612.     BSR    ForeignFreeMem
  613.  
  614.     MOVE.L    A2,A1
  615.     MOVEQ.L    #8,D0
  616.     BSR    ForeignFreeMem
  617.     MOVE.L    (A7)+,A2
  618.     RTS
  619.  
  620. _OPENFONT    
  621.         move.l    a2,-(a7)
  622. ;        CMP.W    #8,4(A0)
  623. ;        BNE.S    .ERR
  624.         MOVE.L    (A0),A1
  625.  
  626.         lea    _FONTTABLE(PC),a2
  627. .next        move.l    (a2)+,a0
  628.         move.l    a0,d0
  629.         beq    .ERR
  630.         bsr    _strcmp
  631.         beq    .found
  632.         addq.l    #4,a2
  633.         bra    .next
  634.  
  635. .found        MOVE.L    (A2),D0
  636.         move.l    (a7)+,a2
  637.         rts
  638.  
  639. .ERR        pea    _LVOOpenFont
  640.         pea    _gfxname
  641.         bra    _emufail
  642.  
  643. _SETFONT    MOVE.L    A0,rp_Font(A1)
  644.         CLR.W    rp_AlgoStyle(A1)
  645.         MOVE.W    tf_YSize(A0),rp_TxHeight(A1)
  646.         MOVE.W    tf_XSize(A0),rp_TxWidth(A1)
  647.         MOVE.W    tf_Baseline(A0),rp_TxBaseline(A1)
  648.         MOVE.W    tf_XSize(A0),rp_TxSpacing(A1)
  649.         RTS
  650.  
  651.  
  652. _PRINTTEXT    ;A0-*STRING, A1-*RASTPORT, D0-CHARCOUNT
  653.         MOVEM.L    D2-D7/A2-A6,-(A7)
  654.         MOVE.L    A0,A2            ;keep stringpointer
  655.         MOVE.L    D0,D2
  656.         MOVE.L    rp_Font(A1),A3        ;get font
  657.         MOVE.L    tf_CharLoc(A3),A4    ;get chardescriptionpointer
  658. .NXPRINT    MOVE.L    D2,-(A7)
  659.         MOVE.L    tf_CharData(A3),A5    ;get chardatapointer
  660.         MOVEQ.L    #0,D3
  661.         MOVE.B    (A2)+,D3        ;get char
  662.         CMP.B    tf_HiChar(A3),D3
  663.         BHI.S    .SPACEPRINT
  664.         CMP.B    tf_LoChar(A3),D3
  665.         BHS.S    .OKPRINT
  666. .SPACEPRINT    MOVE.B    tf_LoChar(A3),D3
  667. .OKPRINT    SUB.B    tf_LoChar(A3),D3
  668.         LSL.W    #2,D3
  669.         MOVE.W    (A4,D3.W),D4    ;get charposition on font - bitoffset
  670.         MOVE.W    2(A4,D3.W),D2        ;bitwidth of char
  671.         MOVE.W    D4,D3
  672.         AND.W    #$F,D4            ;bitshift
  673.         AND.W    #$FFF0,D3
  674.         LSR.W    #3,D3            ;byteoffset of char
  675.         MOVE.W    rp_cp_x(A1),D6        ;x-printposition
  676.         MOVE.W    D6,D5
  677.         AND.W    #$F,D6            ;x-bitshift
  678.         AND.W    #$FFF0,D5
  679.         LSR.W    #3,D5
  680.         EXT.L    D5
  681.         MOVE.W    rp_cp_y(A1),D7        ;y-printposition
  682.         SUB.W    tf_Baseline(A3),D7
  683.         MOVE.L    rp_BitMap(A1),A0
  684.         MULU    (A0),D7        ;memoryoffset of the line by * bytesperrow
  685.         ADD.L    D5,D7        ;memoffset of printposition w/o shift
  686.  
  687.         MOVEQ.L    #0,D1            ;print char
  688. .NXLINE        MOVE.L    (A5,D3.W),D5        ;get charline from charsetdata
  689.         LSL.L    D4,D5
  690.         MOVEQ.L    #-1,D0            ;mask rest out
  691.         LSR.L    D2,D0
  692.         NOT.L    D0
  693.         AND.L    D0,D5        ;chardata in D5, beginning with bit 31
  694.         LSR.L    D6,D5
  695.         LSR.L    D6,D0        ;contain now a 'window' of set bits at printpos
  696.         MOVEM.L    D1/D3/D4/D6,-(A7)
  697.         BTST    #0,rp_AlgoStyle(A1)
  698.         BEQ.S    .NOUNDERLINE
  699.         MOVE.W    tf_YSize(A3),D3
  700.         SUBQ.W    #1,D3
  701.         CMP.W    D3,D1
  702.         BNE.S    .NOUNDERLINE
  703.         MOVE.L    D0,D5
  704. .NOUNDERLINE    MOVE.L    D0,D3
  705.         NOT.L    D3
  706.         MOVEQ.L    #0,D6
  707. .NXPLANE    MOVE.L    D6,D1
  708.         LSL.L    #2,D1
  709.         MOVE.L    bm_Planes(A0,D1.W),A6    ;planepointertable in a6
  710.         MOVE.L    (A6,D7.L),D1        ;screendata
  711.         BTST    #0,rp_DrawMode(A1)    ;test if JAM2
  712.         BNE.S    .JAM2
  713.         OR.L    D5,D1
  714.         BTST    D6,rp_FgPen(A1)
  715.         BNE.S    .MOVETOPLANE
  716.         EOR.L    D5,D1
  717.         BRA.S    .MOVETOPLANE
  718.                         ;now check colors
  719. .JAM2        BTST    D6,rp_BgPen(A1)
  720.         BNE.S    .BGSET
  721.         AND.L    D3,D1            ;clear bits
  722.         BTST    D6,rp_FgPen(A1)
  723.         BEQ.S    .KEEPFG1
  724.         OR.L    D5,D1            ;set bits
  725. .KEEPFG1    BRA.S    .MOVETOPLANE
  726.  
  727. .BGSET        OR.L    D0,D1
  728.         BTST    D6,rp_FgPen(A1)
  729.         BNE.S    .KEEPFG2
  730.         EOR.L    D5,D1
  731. .KEEPFG2
  732. .MOVETOPLANE    MOVE.L    D1,(A6,D7.L)
  733.         ADDQ.L    #1,D6
  734.         CMP.B    bm_Depth(A0),D6        ;for each bitplane
  735.         BLO.S    .NXPLANE
  736.         MOVEM.L    (A7)+,D1/D3/D4/D6
  737.  
  738.         ADD.W    tf_Modulo(A3),A5
  739.         MOVE.L    D7,A6
  740.         ADD.W    bm_BytesPerRow(A0),A6
  741.         MOVE.L    A6,D7
  742.         ADDQ.L    #1,D1
  743.         CMP.W    tf_YSize(A3),D1        ;all lines
  744.         BLO.W    .NXLINE
  745.         ADD.W    D2,rp_cp_x(A1)        ;rp_position moved
  746.         MOVE.L    (A7)+,D2
  747.         SUBQ.L    #1,D2            ;until string is exhausted
  748.         BNE.W    .NXPRINT
  749.         MOVEM.L    (A7)+,D2-D7/A2-A6
  750.  
  751.         moveq.l    #0,D0            ; JFF: old expected return value
  752.         RTS                ; (Little Computer People)
  753.  
  754. _InitBitMap    ;a0=bm d0=depth d1=width d2=height
  755.         addq.w    #7,d1
  756.         lsr.w    #3,d1
  757.         AND.W    #$FFFE,D1            ;LORDS OF WAR
  758.  
  759.         move.w    d1,(bm_BytesPerRow,a0)
  760.         move.w    d2,(bm_Rows,a0)
  761.         clr.b    (bm_Flags,a0)
  762.         move.b    d0,(bm_Depth,a0)
  763.         clr.w    (bm_Pad,a0)
  764.  
  765.         ; put trash in planes data
  766.  
  767.         moveq.l    #7,D0
  768.         move.l    #$BBBBBBBB,D1
  769.         lea    (bm_Planes,A0),A0
  770. .loop
  771.         move.l    D1,(A0)+
  772.         dbf    D0,.loop
  773.         rts
  774.  
  775.  
  776. _MakeVPort    ;a0=view a1=viewport
  777.         movem.l    d2/a2-a4,-(a7)
  778.  
  779.         ; JOTD: store viewport in view structure
  780.         move.l    a1,(v_ViewPort,a0)
  781.  
  782.         move.l    a0,a2
  783.         move.l    a1,a3
  784.         lea    (-$C,A7),A7    ; size of UCopList structure
  785.         move.l    A7,A0
  786.         move.l    #100,D0        ; room for 100 instructions, should be enough
  787.         bsr    _UCopperListInit
  788.         tst.l    d0
  789.         trapeq
  790.         BEQ.W    .ERR
  791.  
  792.         move.l    a2,a0    ; view
  793.         move.l    a3,a1    ; viewport
  794.  
  795.         move.l    d0,a2                ;A2 = coplist
  796.         move.l    a2,(vp_DspIns,a1)
  797.         move.l    (vp_RasInfo,a1),a0
  798.         move.l    (ri_BitMap,a0),a0
  799.  
  800.         move.l    a1,(cl__ViewPort,a2)        ; store viewport
  801.  
  802.         ; build basic copperlist
  803.  
  804.         CMOVE    A7,#diwstrt,#$2981
  805.  
  806.         move.w    #$2981,d0
  807.         move.w    (bm_BytesPerRow,a0),d1
  808.         lsl.w    #3,d1                ;bytes -> pixel
  809.         add.b    d1,d0
  810.         move.w    (bm_Rows,a0),d1
  811.         lsl.w    #8,d1
  812.         add.w    d1,d0
  813.         move.w    d0,d1
  814.         move.w    #diwstop,D0
  815.         bsr    _CMove
  816.         bsr    _CBump
  817.  
  818.  
  819.         CMOVE    A7,#ddfstrt,#$0038
  820.  
  821.         CMOVE    A7,#ddfstop,#$00D0
  822.  
  823.         CMOVE    A7,#bplcon1,#0
  824.         CMOVE    A7,#bpl1mod,#0
  825.         CMOVE    A7,#bpl2mod,#0
  826.  
  827.         moveq    #0,d0
  828.         move.b    (bm_Depth,a0),d0
  829.         ror.w    #4,d0
  830.         or.w    #$200,d0
  831.         move.w    d0,d1
  832.         move.w    #bplcon0,d0
  833.         bsr    _CMove
  834.         bsr    _CBump
  835.  
  836.  
  837.         move.b    (bm_Depth,a0),d2
  838.         lea    (bm_Planes,a0),a0
  839.         move.w    #bplpt,d0
  840. .lp
  841.         move.w    (A0)+,D1
  842.         bsr    _CMove
  843.         bsr    _CBump
  844.         addq.l    #2,D0
  845.         move.w    (A0)+,D1
  846.         bsr    _CMove
  847.         bsr    _CBump
  848.         addq.l    #2,D0
  849.  
  850.         subq.b    #1,d2
  851.         bne.b    .lp
  852.  
  853.         CMOVE    A7,#dmacon,#DMAF_SETCLR+DMAF_RASTER
  854.         CEND    A7
  855.  
  856.         lea    ($C,A7),A7
  857.         movem.l    (a7)+,d2/a2-a4
  858.         rts
  859.  
  860. .ERR        pea    _LVOMakeVPort
  861.         pea    _gfxname
  862.         bra    _emufail
  863.  
  864.  
  865. _MrgCop        ;a1=view
  866.         movem.l    D2/A2/A3/A6,-(A7)
  867.         moveq.l    #0,D2            ; # of copper instructions
  868.  
  869.         move.l    (v_ViewPort,a1),a0    ; a0: viewport
  870.         move.l    (vp_UCopIns,a0),D0    ; gets user copper instructions
  871.         beq.b    .nouser
  872.  
  873.         move.l    D0,A2
  874.         move.l    (ucl_FirstCopList,A2),A2    ; user copper list
  875.  
  876.         move.w    (cl_Count,A2),D2        ; number of user instructions stored
  877. .nouser
  878.         move.l    (vp_SprIns,a0),D0    ; gets user copper instructions
  879.         beq.b    .nosprites
  880.  
  881.         move.l    D0,A2
  882.         add.w    (cl_Count,A2),D2        ; adds number of sprite instructions
  883. .nosprites
  884.         move.l    (vp_DspIns,a0),a2
  885.         move.l    a0,(cl__ViewPort,A2)        ; store viewport
  886.         add.w    (cl_Count,A2),D2        ; adds number of display instructions
  887.  
  888.         add.l    D2,D2
  889.         add.l    D2,D2        ; D2 * 4
  890.  
  891.         move.l    D2,D0
  892.         movem.l    A0/A1/A6,-(A7)
  893.         move.l    (gb_ExecBase,A6),A6
  894.         move.l    #MEMF_CHIP|MEMF_CLEAR,D1
  895.         JSRLIB    AllocVec
  896.         movem.l    (A7)+,A0/A1/A6
  897.         move.l    D0,(cl_CopLStart,A2)    ; store total clist in DspList !!
  898.         beq    .fail
  899.  
  900.         ; now convert available copperlists to hardware info
  901.  
  902.         move.l    D0,A3
  903.  
  904.         move.l    (vp_DspIns,a0),D0
  905.         bsr    mrgcop_convert
  906.  
  907.         move.l    (vp_UCopIns,a0),D0
  908.         beq.b    .nousermrg
  909.         move.l    D0,A2
  910.         move.l    (ucl_FirstCopList,A2),D0    ; user copper list
  911.         bsr    mrgcop_convert
  912. .nousermrg
  913.         move.l    (vp_SprIns,a0),D0
  914.         beq.b    .nosprmrg
  915.         bsr    mrgcop_convert
  916. .nosprmrg
  917.  
  918.         move.l    #$FFFFFFFE,(A3)
  919.  
  920.         ; conversion done, set copperlist
  921.  
  922.         move.l    (vp_DspIns,a0),a2
  923.         move.l    (cl_CopLStart,A2),(v_LOFCprList,a1)
  924.  
  925. .exit
  926.         movem.l    (A7)+,D2/A2/A3/A6
  927.         rts
  928.  
  929. .fail:
  930.     GFXFAIL    _LVOMrgCop
  931.  
  932. ; < D0: CopList structure
  933. ; <> A3: pointer on hardware buffer
  934.  
  935. mrgcop_convert:
  936.     tst.l    D0
  937.     beq.b    .exit
  938.     
  939.     movem.l    D0-D2/A0,-(A7)
  940.     move.l    D0,A0        ; coplist structure
  941.     moveq.l    #0,D0
  942.     move.w    (cl_Count,A0),D2    ; # of instructions
  943.     move.l    (cl_CopIns,A0),A0    ; start of list
  944.  
  945. .loop
  946.     move.w    (2,A0),d0
  947.     move.w    (4,A0),d1
  948.     tst.w    (A0)
  949.     beq.b    .move
  950. .wait
  951.     cmp.w    #10000,D0
  952.     beq.b    .quit        ; end of copperlist
  953.     move.b    d0,(A3)+
  954.     move.b    d1,(A3)+
  955.     move.w    #$FFFE,(A3)+
  956.     bra    .next
  957. .move
  958.     move.w    d0,(A3)+
  959.     move.w    d1,(A3)+
  960. .next
  961.     addq.l    #6,A0
  962.     subq.l    #1,D2
  963.     bne.b    .loop
  964. .quit
  965.     movem.l    (A7)+,D0-D2/A0
  966. .exit
  967.     rts
  968.  
  969. _LoadView    ;a1=view
  970.         move.l    a1,d0
  971.         beq    .noview
  972.         move.l    (v_LOFCprList,a1),d0
  973.         beq.b    .fail
  974.  
  975.         move.l    d0,(gb_LOFlist,a6)
  976.         move.l    d0,(_custom+cop2lc)
  977.         move.l    d0,OSM_COPLIST2
  978.         rts
  979.  
  980. .noview
  981.         CLR.L    (gb_ActiView,a6)
  982.         MOVE.L    #STDCOPPER,(gb_LOFlist,a6)
  983.         move.l    (v_SHFCprList,a1),(gb_SHFlist,a6)
  984.         rts
  985.         
  986. .fail
  987.         GFXFAIL    _LVOLoadView
  988.  
  989. ; JOTD. untested, unplugged
  990. ;a0=viewport a1=colors table
  991.     ifeq    1
  992. _LoadRGB32:
  993.     cmp.l    #0,A1
  994.     beq.b    .exit
  995.     movem.l    D2/D3/D5,-(A7)
  996.     lea    12(A7),A7
  997.  
  998.     lea    _custom,A0
  999.  
  1000.     moveq.l    #0,D5
  1001.     moveq.l    #0,D3
  1002.     moveq    #0,D2        ; bank number
  1003.  
  1004.     move.w    (A1)+,D0    ; total # of colors to load
  1005.     move.w    (A1)+,D1    ; first color number to load
  1006.     add.w    D1,D1        ; D1*2
  1007.     subq.w    #1,D0
  1008. .loop
  1009.  
  1010.     move.l    (A1)+,(A7)    ; red
  1011.     beq.b    .out
  1012.     move.l    (A1)+,4(A7)    ; green
  1013.     move.l    (A1)+,8(A7)    ; blue
  1014.  
  1015.     ; compute current bank number
  1016.     ; & sets the correct color bank
  1017.  
  1018.     move.w    D1,D3
  1019.     and.w    #$E000,D3
  1020.     bset    #9,D3    ; higher colors
  1021.  
  1022.     ; compute current color
  1023.  
  1024.     move.w    D1,D2
  1025.     and.w    #$1F,D2        ; D2 % 32
  1026.     add.w    D2,D2        ; D2 * 2
  1027.  
  1028.     ; compose RGB high color
  1029.  
  1030.     move.b    (A7),D5        ; red
  1031.     swap    D5
  1032.     move.w    4(A7),D5    ; green
  1033.     move.b    8(A7),D5    ; blue
  1034.     move.w    D2,(bplcon3,A0)
  1035.     move.w    D5,(A0,D2.W)
  1036.  
  1037.     ; compose RGB low color
  1038.  
  1039.     move.b    1(A7),D5        ; red
  1040.     swap    D5
  1041.     move.w    5(A7),D5    ; green
  1042.     move.b    9(A7),D5    ; blue
  1043.     bclr    #9,D3    ; lower colors
  1044.     move.w    D2,(bplcon3,A0)
  1045.     move.w    D5,(A0,D2.W)
  1046.  
  1047.     addq.l    #1,D1
  1048.     dbf    D0,.loop
  1049. .out
  1050.     lea    -12(A7),A7
  1051.     movem.l    (A7)+,D2/D3/D5
  1052. .exit
  1053.     rts
  1054.     endif
  1055.  
  1056.  
  1057. _LoadRGB4    ;a0=viewport a1=colors d0=count
  1058.         bsr    _waitvb
  1059.         lea    (_custom+color),a0
  1060. .cpy        move.w    (a1)+,(a0)+
  1061.         subq.w    #1,d0
  1062.         bne.b    .cpy
  1063.         rts
  1064.  
  1065. _SetRGB4    ;a0=viewport d0=pen d1=red d2=green d3=blue
  1066.     ;    bsr    _waitvb
  1067.  
  1068.         ; compose color in D1
  1069.  
  1070.         lsl.w    #4,d1
  1071.         or.w    d2,d1
  1072.         lsl.w    #4,d1
  1073.         or.w    d3,d1
  1074.         ext.w    d0
  1075.  
  1076.         ; JOTD, disabled my code
  1077.         ifeq 1
  1078.         ; update colormap if exists
  1079.  
  1080.         move.l    (vp_ColorMap,A0),A0
  1081.         cmp.l    #0,A0
  1082.         beq.b    .skipcm
  1083.  
  1084.         move.l    (cm_ColorTable,A0),A0
  1085.         add.w    D0,A0
  1086.         add.w    D0,A0
  1087.         move.w    D1,(A0)
  1088. .skipcm
  1089.         endif
  1090.  
  1091.         ; updates hardware registers
  1092.  
  1093.         lea    (_custom+color),a1
  1094.         add.w    d0,a1
  1095.         add.w    d0,a1
  1096.         move.w    d1,(a1)
  1097.         rts
  1098.  
  1099. ; < A0: colormap
  1100. ; < D0: color to get
  1101.  
  1102. _GetRGB4:
  1103.     move.l    (cm_ColorTable,A0),A1
  1104.     add.l    D0,D0
  1105.     add.l    D0,D0
  1106.     add.l    D0,A1
  1107.     moveq.l    #0,D0
  1108.     moveq.l    #0,D1
  1109.     move.b    (A1)+,D0
  1110.     move.b    (A1)+,D1
  1111.     lsl    #4,D1
  1112.     or.b    D1,D0
  1113.     move.b    (A1)+,D1
  1114.     lsl    #8,D1
  1115.     or.b    D1,D0
  1116.     rts
  1117.  
  1118. _VBeamPos    move.l    (_custom+vposr),d0
  1119.         lsr.l    #8,d0
  1120.         and.l    #$1ff,d0
  1121.         rts
  1122.  
  1123. _WaitTOF    BSR.w    _waitvb
  1124.         rts
  1125.  
  1126. _WaitBOVP:
  1127.         bsr.w    _waitvb        ; -- added by JOTD
  1128.         rts            ; -- I know this is not the accurate function
  1129.  
  1130. _ReadPixel    ;d0=x d1=y a1=rastport
  1131.         move.l    (rp_BitMap,a1),a0
  1132.         ext.l    d0
  1133.         ror.l    #3,d0
  1134.         cmp.w    (bm_BytesPerRow,a0),d0
  1135.         bhs    .bad
  1136.         cmp.w    (bm_Rows,a0),d1
  1137.         bhs    .bad
  1138.         mulu    (bm_BytesPerRow,a0),d1
  1139.         add.w    d0,d1            ;byte offset
  1140.         rol.l    #3,d0            ;bit offset
  1141.         
  1142.         movem.l    d2-d4,-(a7)
  1143.         moveq    #0,d2
  1144.         moveq    #0,d3
  1145.         move.b    (bm_Depth,a0),d4
  1146.         lea    (bm_Planes,a0),a0
  1147.         
  1148. .next        move.l    (a0)+,a1
  1149.         btst    d0,(a1,d1.l)
  1150.         beq    .1
  1151.         bset    d2,d3
  1152. .1        addq.l    #1,d2
  1153.         cmp.b    d2,d4
  1154.         bhi    .next
  1155.         
  1156.         move.l    d3,d0
  1157.         movem.l    (a7)+,d2-d4
  1158.         rts
  1159.  
  1160. .bad        moveq    #-1,d0
  1161.         rts
  1162.  
  1163. ; <A1: rastport
  1164. ; <D0: X
  1165. ; <D1: Y
  1166. ; >D0: 0 if OK, -1 if error
  1167.  
  1168. _WritePixel    ;d0=x d1=y a1=rastport
  1169.         move.l    (rp_BitMap,a1),a0
  1170.         ext.l    d0
  1171.         ror.l    #3,d0
  1172.         cmp.w    (bm_BytesPerRow,a0),d0
  1173.         bhs    .bad
  1174.         cmp.w    (bm_Rows,a0),d1
  1175.         bhs    .bad
  1176.         mulu    (bm_BytesPerRow,a0),d1
  1177.         add.w    d0,d1            ;byte offset
  1178.         rol.l    #3,d0            ;bit offset
  1179.         
  1180.         movem.l    d2-d4,-(a7)
  1181.         moveq    #0,d2
  1182.         move.b    (rp_FgPen,a1),d3
  1183.         move.b    (bm_Depth,a0),d4
  1184.         lea    (bm_Planes,a0),a0
  1185.         
  1186. .next        move.l    (a0)+,a1
  1187.         btst    d2,d3
  1188.         beq.b    .clear
  1189. .set        bset    d0,(a1,d1.w)
  1190.         bra.b    .1
  1191. .clear        bclr    d0,(a1,d1.w)
  1192. .1        addq.l    #1,d2
  1193.         cmp.b    d2,d4
  1194.         bhi.b    .next
  1195.         
  1196.         move.l    d3,d0
  1197.         movem.l    (a7)+,d2-d4
  1198.         rts
  1199.  
  1200. .bad        moveq    #-1,d0
  1201.         rts
  1202.  
  1203. ; added by JOTD. Untested
  1204.  
  1205. ; <A1: rastport
  1206. ; <D0: pen
  1207.  
  1208. _SetRast:
  1209.     movem.l    D2-D7/A2-A6,-(A7)
  1210.     bsr    _SetAPen
  1211.     moveq.l    #0,D0    ; xmin
  1212.     moveq.l    #0,D1    ; ymin
  1213.     move.l    #319,D2    ; xmax
  1214.     move.l    #199,D3 ; ymax
  1215.     bsr    _RectFill
  1216.     movem.l    (A7)+,D2-D7/A2-A6
  1217.     rts
  1218.  
  1219. ; added by JOTD. Not optimized and not tested AT ALL, disabled
  1220.  
  1221.     ;d0=xmin d1=ymin d2=xmax d3=ymax a1=rastport
  1222. _RectFill:
  1223.     rts
  1224.     movem.l    a2/d2-d7,-(A7)
  1225.  
  1226.     move.l    d0,d7    ; save D0 (xmin)
  1227. .loopx
  1228. .loopy
  1229.     move.w    d0,d5    ; save current X
  1230.     move.w    d1,d6    ; save current Y
  1231.     move.l    a1,a2    ; save rastport
  1232.     bsr    _WritePixel    ; writes a pixel
  1233.     move.l    a2,a1    ; restores rastport
  1234.     move.w    d5,d0    ; restores current X
  1235.     move.w    d6,d1    ; restores current Y
  1236.     addq.w    #1,d0    ; next X
  1237.     cmp.w    d2,d0    ; reached xmax?
  1238.     bcc.b    .nexty    ; out
  1239.     bra.b    .loopx    ; no, loop
  1240. .nexty
  1241.     move.w    d7,d0    ; reload D0 with xmin
  1242.     addq.w    #1,d1    ; next Y
  1243.     cmp.w    d3,d1    ; reached ymax?
  1244.     bcc.b    .exit
  1245.     bra.b    .loopy    ; no, loop
  1246. .exit
  1247.     movem.l    (A7)+,a2/d2-d7
  1248.     rts
  1249.  
  1250.  
  1251. **************************************************************************
  1252. *    SPRITES
  1253. **************************************************************************
  1254.  
  1255. _FreeSprite    ;d0=pick
  1256.  
  1257.         ; frees the sprite in gfxbase
  1258.  
  1259.         bclr    d0,(gb_SpriteReserved,a6)
  1260.  
  1261.         ; invalidate the sprite
  1262.  
  1263.         add.l    D0,D0
  1264.         add.l    D0,D0
  1265.         lea    _sprites,A0
  1266.         move.l    #-1,(A0,D0.W)
  1267.         rts
  1268.  
  1269. _GetSprite    ;a0=sprite d0=pick
  1270.         tst.w    d0
  1271.         bmi    .any
  1272.         bset    d0,(gb_SpriteReserved,a6)
  1273.         bne    .error
  1274. .end        move.w    d0,(ss_num,a0)    ; JOTD: bugfix: was a move.b
  1275.         ext.l    d0
  1276.         rts
  1277.  
  1278. .error        moveq    #-1,d0
  1279.         rts
  1280.  
  1281. .any        cmp.b    (gb_SpriteReserved,a6),d0
  1282.         beq    .error
  1283. .next        addq.w    #1,d0
  1284.         bset    d0,(gb_SpriteReserved,a6)
  1285.         bne    .next
  1286.         bra    .end
  1287.  
  1288. _ChangeSprite    ;a0=viewport a1=simplesprite a2=data
  1289.         moveq    #0,d0
  1290.         move.w    (ss_num,a1),d0    ; JOTD: bugfix: was a move.b
  1291.         lsl.w    #2,d0
  1292.         lea    (_sprites),a0
  1293.         move.l    a2,(a0,d0.w)
  1294.         move.w    #DMAF_SETCLR!DMAF_SPRITE,(_custom+dmacon)
  1295.         rts
  1296.  
  1297. _MoveSprite    ;a0=viewport a1=simplesprite d0=x d1=y
  1298.         ;129,41 top,left
  1299.         move.l    d2,-(a7)
  1300.         moveq    #0,d2
  1301.         move.w    (ss_num,a1),d2    ; JOTD: bugfix: was a move.b
  1302.         lsl.w    #2,d2
  1303.         lea    (_sprites),a0
  1304.         move.l    (a0,d2.w),a0
  1305.         add.w    #129,d0            ;d0 hor
  1306.         add.w    #41,d1            ;d1 top
  1307.         move.w    d1,d2
  1308.         add.w    (ss_height,a1),d2    ;d2 bottom
  1309.         move.b    d1,(a0)+        ;top7..top0
  1310.         ror.w    #1,d0
  1311.         move.b    d0,(a0)+        ;hor8..hor1
  1312.         move.b    d2,(a0)+        ;bot7..bot0
  1313.         lsr.w    #8,d1
  1314.         lsl.w    #7,d2
  1315.         addx.w    d2,d2
  1316.         addx.w    d1,d1
  1317.         addx.w    d0,d0
  1318.         addx.w    d1,d1
  1319.         move.b    d1,(a0)+
  1320.         move.l    (a7)+,d2
  1321.         rts
  1322.  
  1323. **************************************************************************
  1324. *    BLITTER
  1325. **************************************************************************
  1326.  
  1327. _WaitBlit
  1328. .wait        
  1329.     tst.b    (_ciaa)
  1330.     tst.b    (_ciaa)
  1331.     btst    #DMAB_BLTDONE-8,(_custom+dmaconr)
  1332.     bne.b    .wait
  1333.     tst.b    (_ciaa)
  1334.     rts
  1335.     
  1336. _ClipBlit
  1337.     move.l    #$FF,D7
  1338.  
  1339. _BltBitMap    ;a0=sbitmap d0=sx d1=sy
  1340.         ;a1=dbitmap d2=dx d3=dy
  1341.         ;d4=width d5=height d6=minterm d7=mask a2=buffer
  1342.  
  1343.         movem.l    d2-d7/a2-a3,-(a7)
  1344.  
  1345.         lea    (_custom),a3
  1346.  
  1347.         mulu    (bm_BytesPerRow,a0),d1
  1348.         ext.l    d0
  1349.         ror.l    #4,d0
  1350.         add.w    d0,d1
  1351.         add.w    d0,d1            ;d1 = byte offset src
  1352.  
  1353.         mulu    (bm_BytesPerRow,a1),d3
  1354.         ext.l    d2
  1355.         ror.l    #4,d2
  1356.         add.w    d2,d3
  1357.         add.w    d2,d3            ;d3 = byte offset dest
  1358.  
  1359.         lsl.w    #6,d5            ;height
  1360.         
  1361.         and.w    #$00f0,d6
  1362.         or.w    #$070a,d6
  1363.         bsr    _WaitBlit
  1364.         move.w    d6,(bltcon0,a3)
  1365.         
  1366.         moveq    #-1,d6
  1367.         move.w    d6,(bltadat,a3)
  1368.         clr.w    d2
  1369.         rol.l    #4,d2            ;d2 = amount of pixels to skip in the first word in dest
  1370.         lsr.w    d2,d6            ;d6.w = afwm
  1371.         swap    d6
  1372.         addq.w    #1,d5            ;d5 = width++ (the first word)
  1373.         sub.w    #16,d4
  1374.         add.w    d2,d4            ;d4 = pixels left to copy
  1375.         ext.l    d4
  1376.         ror.l    #4,d4
  1377.         add.w    d4,d5            ;d5.w = size
  1378.         clr.w    d4
  1379.         rol.l    #4,d4            ;d4 = pixels left to copy (0..15)
  1380.         beq    .1
  1381.         addq.w    #1,d5            ;d5 = width++ (the last word)
  1382.         lsr.w    d4,d6            ;d6.w = ~(alwm)
  1383.         not.w    d6
  1384. .1        move.l    d6,(bltafwm,a3)
  1385.         
  1386.         clr.w    d0
  1387.         rol.l    #4,d0            ;pixel offset src
  1388.         sub.w    d0,d2
  1389.     ;    spl    d4            ;d4 = 0 if first src word must be preloaded (dma-b)
  1390.         bpl    .2
  1391.     ;this works only if the destination is word aligned !!!!!!
  1392.     ;(in deuteros it is...) normally a second blit is necessary in this case
  1393.         addq.w    #1,d5            ;bltsize++
  1394.         subq.w    #2,d3            ;dst-2
  1395.         move.w    #0,(bltafwm,a3)
  1396.         add.w    #16,d2
  1397. .2        ror.w    #4,d2
  1398.  
  1399.         bsr    _WaitBlit    ; temp
  1400.  
  1401.         move.w    d2,(bltcon1,a3)
  1402.         
  1403.         move.w    d5,d0
  1404.         and.w    #$003f,d0
  1405.         add.w    d0,d0
  1406.         move.w    (bm_BytesPerRow,a0),d2
  1407.         sub.w    d0,d2
  1408.         move.w    d2,(bltbmod,a3)
  1409.         move.w    (bm_BytesPerRow,a1),d2
  1410.         sub.w    d0,d2
  1411.         move.w    d2,(bltcmod,a3)
  1412.         move.w    d2,(bltdmod,a3)
  1413.  
  1414.         moveq    #0,d6
  1415. .do        btst    d6,d7            ;mask ?
  1416.         beq    .next
  1417.  
  1418.         lsl.w    #2,d6
  1419.         move.l    (bm_Planes,a0,d6.w),a2
  1420.         add.l    d1,a2
  1421.         move.l    (bm_Planes,a1,d6.w),d0
  1422.         add.l    d3,d0
  1423.         bsr    _WaitBlit
  1424.         movem.l    d0/a2,(bltcpt,a3)
  1425.         move.l    d0,(bltdpt,a3)
  1426.         move.w    d5,(bltsize,a3)
  1427.         lsr.w    #2,d6
  1428.  
  1429. .next        addq.w    #1,d6
  1430.         cmp.b    (bm_Depth,a0),d6
  1431.         beq    .end
  1432.         cmp.b    (bm_Depth,a1),d6
  1433.         bne    .do
  1434. .end
  1435.         movem.l    (a7)+,d2-d7/a2-a3
  1436.         rts
  1437.  
  1438. _BltTemplate    ;a0=src d0=bitoffset d1=modulo
  1439.         ;a1=rp d2=x d3=y d4=width d5=height
  1440.  
  1441.         movem.l    d2-d7/a2-a3,-(a7)
  1442.         lea    (_custom),a3
  1443.  
  1444.         ext.l    d0
  1445.         ror.l    #4,d0
  1446.         add.w    d0,a0
  1447.         add.w    d0,a0            ;a0 = src ptr
  1448.  
  1449.         move.l    (rp_BitMap,a1),a2
  1450.         mulu    (bm_BytesPerRow,a2),d3
  1451.         ext.l    d2
  1452.         ror.l    #4,d2
  1453.         add.w    d2,d3
  1454.         add.w    d2,d3            ;d3 = byte offset dest
  1455.  
  1456.         lsl.w    #6,d5            ;height
  1457.         
  1458.         bsr    _WaitBlit
  1459.         move.w    #$07aa,(bltcon0,a3)
  1460.         
  1461.         moveq    #-1,d6
  1462.         move.w    d6,(bltadat,a3)
  1463.         clr.w    d2
  1464.         rol.l    #4,d2            ;d2 = amount of pixels to skip in the first word in dest
  1465.         lsr.w    d2,d6            ;d6.w = afwm
  1466.         swap    d6
  1467.         addq.w    #1,d5            ;d5 = width++ (the first word)
  1468.         sub.w    #16,d4
  1469.         add.w    d2,d4            ;d4 = pixels left to copy
  1470.         ext.l    d4
  1471.         ror.l    #4,d4
  1472.         add.w    d4,d5            ;d5.w = size
  1473.         clr.w    d4
  1474.         rol.l    #4,d4            ;d4 = pixels left to copy (0..15)
  1475.         beq    .1
  1476.         addq.w    #1,d5            ;d5 = width++ (the last word)
  1477.         lsr.w    d4,d6            ;d6.w = ~(alwm)
  1478.         not.w    d6
  1479. .1        move.l    d6,(bltafwm,a3)
  1480.         
  1481.         clr.w    d0
  1482.         rol.l    #4,d0            ;pixel offset src
  1483.         sub.w    d0,d2
  1484.     ;    spl    d4            ;d4 = 0 if first src word must be preloaded (dma-b)
  1485.         bpl    .2
  1486.     ;this works only if the destination is word aligned !!!!!!
  1487.     ;(in deuteros it is...) normally a second blit is neccessary in this case
  1488.         addq.w    #1,d5            ;bltsize++
  1489.         subq.w    #2,d3            ;dst-2
  1490.         move.w    #0,(bltafwm,a3)
  1491.         add.w    #16,d2
  1492. .2        ror.w    #4,d2
  1493.         move.w    d2,(bltcon1,a3)
  1494.         
  1495.         move.w    d5,d0
  1496.         and.w    #$003f,d0
  1497.         add.w    d0,d0
  1498.         move.w    d1,d2
  1499.         sub.w    d0,d2
  1500.         move.w    d2,(bltbmod,a3)
  1501.         move.w    (bm_BytesPerRow,a2),d2
  1502.         sub.w    d0,d2
  1503.         move.w    d2,(bltcmod,a3)
  1504.         move.w    d2,(bltdmod,a3)
  1505.  
  1506.         moveq    #0,d6
  1507. .do        lsl.w    #2,d6
  1508.         move.l    (bm_Planes,a2,d6.w),d0
  1509.         add.l    d3,d0
  1510.         bsr    _WaitBlit
  1511.         movem.l    d0/a0,(bltcpt,a3)
  1512.         move.l    d0,(bltdpt,a3)
  1513.         move.w    d5,(bltsize,a3)
  1514.         lsr.w    #2,d6
  1515.  
  1516. .next        addq.w    #1,d6
  1517.         cmp.b    (bm_Depth,a2),d6
  1518.         bne    .do
  1519.  
  1520.         movem.l    (a7)+,d2-d7/a2-a3
  1521.         rts
  1522.  
  1523. ; AllocBitMap, direct 3.0 ROM rip, not sure it works...
  1524.  
  1525. _AllocBitMap:
  1526.     MOVEM.L    D3/D4,-(A7)
  1527.     CMP.L    #$00000100,D3
  1528.     BCC.B    .LB_994E
  1529.     MOVEM.L    D0/D1/A6,-(A7)
  1530.     CMPA.W    #$0000,A0
  1531.     BEQ.B    .LB_9900
  1532.     CMP.B    $0005(A0),D2
  1533.     BNE.B    .LB_9900
  1534.     CMPI.W    #$805C,$0006(A0)
  1535.     BNE.B    .LB_9900
  1536.     BSET    #$02,D3
  1537. .LB_9900    MOVE.L    $01A4(A6),A6
  1538.     MOVEQ    #$08,D0
  1539.     MOVE.W    D2,D1
  1540.     BTST    #$04,D3
  1541.     BNE.B    .LB_9914
  1542.     MOVEQ    #$28,D0
  1543.     SUBQ.W    #8,D1
  1544.     BLE.B    .LB_991A
  1545. .LB_9914    ADD.W    D1,D1
  1546.     ADD.W    D1,D1
  1547.     ADD.W    D1,D0
  1548. .LB_991A    MOVE.L    #$00010000,D1
  1549.     JSRLIB    AllocVec
  1550.     MOVE.L    D0,A0
  1551.     TST.L    D0
  1552.     MOVEM.L    (A7)+,D0/D1/A6
  1553.     BEQ.B    .LB_994E
  1554.     MOVE.L    A0,-(A7)
  1555.     BSR.W    .LB_97AA
  1556.     TST.L    D0
  1557.     BNE.B    .LB_9940
  1558.     MOVE.L    (A7)+,D0
  1559.     MOVEM.L    (A7)+,D3/D4
  1560.     RTS    
  1561. .LB_9940    MOVE.L    (A7)+,A1
  1562.     MOVE.L    A6,-(A7)
  1563.     MOVE.L    $01A4(A6),A6
  1564.     JSR    -690(A6)
  1565.     MOVE.L    (A7)+,A6
  1566. .LB_994E    MOVEQ    #$00,D0
  1567.     MOVEM.L    (A7)+,D3/D4
  1568.     RTS    
  1569.  
  1570.  
  1571. .LB_97AA    MOVEM.L    D2-D4/A2/A3/A6,-(A7)
  1572.     MOVEQ    #$10,D4
  1573.     BTST    #$01,D3
  1574.     BEQ.B    .LB_97CA
  1575.     SWAP    D3
  1576.     CLR.W    D3
  1577.     MOVE.B    $00ED(A6),D3
  1578.     MOVE.L    $01A8(A6),A1
  1579.     MOVE.B    $00(A1,D3.W),D3
  1580.     ASL.B    D3,D4
  1581.     SWAP    D3
  1582. .LB_97CA    SUBQ.W    #1,D4
  1583.     ADD.W    D4,D0
  1584.     ADDQ.W    #1,D4
  1585.     NEG.W    D4
  1586.     AND.W    D4,D0
  1587.     MOVE.W    D1,$0002(A0)
  1588.     LSR.W    #3,D0
  1589.     CMP.W    #$0002,D2
  1590.     BLT.B    .LB_97FA
  1591.     BTST    #$00,$00EC(A6)
  1592.     BEQ.B    .LB_97FA
  1593.     CMP.W    #$0FFD,D0
  1594.     BGT.B    .LB_97FA
  1595.     CMP.W    #$0FFD,D1
  1596.     BGT.B    .LB_97FA
  1597.     BTST    #$02,D3
  1598.     BNE.B    .LB_9848
  1599. .LB_97FA    MOVE.W    D0,(A0)
  1600.     MULU.W    D1,D0
  1601.     CLR.B    $0005(A0)
  1602.     SUBQ.W    #1,D2
  1603.     MOVE.L    $01A4(A6),A6
  1604.     MOVE.L    D0,D4
  1605.     MOVEQ    #$02,D1
  1606.     BTST    #$00,D3
  1607.     BEQ.B    .LB_9818
  1608.     OR.L    #$00010000,D1
  1609. .LB_9818    MOVE.L    D1,D3
  1610.     LEA    $0008(A0),A2
  1611.     MOVE.L    A0,A3
  1612. .LB_9820    MOVE.L    D4,D0
  1613.     MOVE.L    D3,D1
  1614.     JSR    -198(A6)
  1615.     MOVE.L    D0,(A2)+
  1616.     BEQ.B    .LB_983C
  1617.     ADDQ.B    #1,$0005(A3)
  1618.     DBF    D2,.LB_9820
  1619.     MOVEM.L    (A7)+,D2-D4/A2/A3/A6
  1620.     MOVEQ    #$00,D0
  1621.     RTS    
  1622. .LB_983C    MOVE.L    A3,A0
  1623.     MOVEM.L    (A7)+,D2-D4/A2/A3/A6
  1624.     BSR.B    .LB_98A2
  1625.     MOVEQ    #-$01,D0
  1626.     RTS    
  1627. .LB_9848    MOVEM.L    D0/D1/A6,-(A7)
  1628.     MOVE.L    D0,D4
  1629.     MOVE.L    A0,A3
  1630.     MOVE.B    D2,$0005(A0)
  1631.     MULU.W    D2,D0
  1632.     MOVE.W    D0,(A0)
  1633.     MULU.W    $0002(A0),D0
  1634.     MOVEQ    #$02,D1
  1635.     BTST    #$00,D3
  1636.     BEQ.B    .LB_986A
  1637.     OR.L    #$00010000,D1
  1638. .LB_986A    MOVE.L    $01A4(A6),A6
  1639.     JSR    -198(A6)
  1640.     TST.L    D0
  1641.     BNE.B    .LB_9880
  1642.     MOVEM.L    (A7)+,D0/D1/A6
  1643.     MOVE.L    A3,A0
  1644.     BRA.W    .LB_97FA
  1645. .LB_9880    SUBQ.W    #1,D2
  1646.     LEA    $0008(A3),A2
  1647.     EXT.L    D4
  1648. .LB_9888    MOVE.L    D0,(A2)+
  1649.     ADD.L    D4,D0
  1650.     DBF    D2,.LB_9888
  1651.     MOVE.W    #$805C,$0006(A3)
  1652.     LEA    $000C(A7),A7
  1653.     MOVEM.L    (A7)+,D2-D4/A2/A3/A6
  1654.     MOVEQ    #$00,D0
  1655.     RTS    
  1656. .LB_98A2    MOVEM.L    D2/D3/A2/A6,-(A7)
  1657.     MOVEQ    #$00,D2
  1658.     MOVE.B    $0005(A0),D2
  1659.     CMPI.W    #$805C,$0006(A0)
  1660.     BNE.B    .LB_98B6
  1661.     MOVEQ    #$01,D2
  1662. .LB_98B6    MOVE.L    $01A4(A6),A6
  1663.     MOVE.W    (A0),D3
  1664.     MULU.W    $0002(A0),D3
  1665.     LEA    $0008(A0),A2
  1666.     BRA.B    .LB_98CE
  1667. .LB_98C6    MOVE.L    (A2)+,A1
  1668.     MOVE.L    D3,D0
  1669.     JSR    -210(A6)
  1670. .LB_98CE    DBF    D2,.LB_98C6
  1671.     MOVEM.L    (A7)+,D2/D3/A2/A6
  1672.     RTS    
  1673.  
  1674.  
  1675. abm_table:
  1676.     DC.B    $00,$01,$01,$02,$00,$E0,$00,$00
  1677.     DC.B    $01,$00,$02,$00,$01,$06,$0C,$00
  1678.     DC.B    $01,$80,$01,$FE,$0C,$00,$01,$FC
  1679.     DC.B    $00,$00,$00,$8E,$01,$81,$00,$90
  1680.     DC.B    $02,$81,$01,$E4,$00,$00,$00,$92
  1681.     DC.B    $00,$18,$00,$94,$00,$20,$01,$04
  1682.     DC.B    $00,$24,$01,$FE,$0C,$00,$01,$FE
  1683.     DC.B    $00,$00,$01,$FE,$00,$00,$01,$FE
  1684.     DC.B    $00,$00,$01,$FE,$00,$00,$01,$FE
  1685.     DC.B    $00,$00,$01,$FE,$00,$00,$01,$FE
  1686.     DC.B    $00,$00,$0C,$01,$FF,$FE,$0C,$01
  1687.     DC.B    $FF,$FE,$00,$8A,$00,$00,$01,$06
  1688.     DC.B    $0C,$00,$FF,$FF,$FF,$FE,$63,$69
  1689.     DC.B    $61,$62,$2E,$72,$65,$73,$6F,$75
  1690.     DC.B    $72,$63,$65,$00,$00,$00,$00,$00
  1691.     DC.B    $FF,$F8,$FF,$F0,$FF,$F0,$FF,$E0
  1692.     DC.B    $FF,$F8,$FF,$F8,$FF,$F8,$FF,$F0
  1693.     DC.B    $FF,$F8,$FF,$F8,$FF,$F8,$FF,$F8
  1694.     DC.B    $FF,$F8,$FF,$F0,$FF,$F0,$FF,$E0
  1695.     DC.B    $FF,$F8,$FF,$F8,$FF,$F8,$FF,$F0
  1696.     DC.B    $FF,$F8,$FF,$F8,$FF,$F8,$FF,$F8
  1697.     DC.B    $FF,$F8,$FF,$F0,$FF,$F0,$FF,$E0
  1698.     DC.B    $FF,$FC,$FF,$F8,$FF,$F8,$FF,$F0
  1699.     DC.B    $FF,$FE,$FF,$FC,$FF,$FC,$FF,$F8
  1700.     DC.B    $00,$08,$00,$08,$00,$08,$00,$08
  1701.     DC.B    $00,$04,$00,$08,$00,$08,$00,$08
  1702.     DC.B    $00,$02,$00,$04,$00,$04,$00,$08
  1703.     DC.B    $64,$65,$66,$61,$75,$6C,$74,$2E
  1704.     DC.B    $6D,$6F,$6E,$69,$74,$6F,$72,$00
  1705.     DC.B    $64,$65,$66,$61,$75,$6C,$74,$2E
  1706.     DC.B    $6D,$6F,$6E,$69,$74,$6F,$72,$00
  1707.     DC.B    $6E,$74,$73,$63,$2E,$6D,$6F,$6E
  1708.     DC.B    $69,$74,$6F,$72,$00,$00,$70,$61
  1709.     DC.B    $6C,$2E,$6D,$6F,$6E,$69,$74,$6F
  1710.     DC.B    $72,$00,$00,$00,$80,$00,$00,$0F
  1711.     DC.B    $00,$00,$00,$00,$80,$00,$00,$20
  1712.  
  1713. ;<a0 src bitmap-struct
  1714. ;<a1 dest rastport-struct
  1715. ;<a2 mask bitmap, size as the one in a0
  1716. ;<d0 x src bitmap
  1717. ;<d1 y src bitmap
  1718. ;<d2 x dest rastport
  1719. ;<d3 y dest rastport
  1720. ;<d4 width
  1721. ;<d5 height
  1722. ;<d6 minterm
  1723.  
  1724. ;internal:
  1725. ;channel a-mask
  1726. ;channel b-src data
  1727. ;channel c-dest data as src
  1728. ;a3 byteoffset&fffe for start in src/mask bitplane
  1729. ;a4 byteoffset&fffe for start in dest bitplane
  1730. ;a6 value for dest bitmap-struct (from rastport); later $dff000
  1731. ;minterm is ignored, i dont know why it doesnt work right with it, i use
  1732. ;  $CA instead which works (at least for Traders)
  1733. ;d6/d7 scratch
  1734. ;
  1735. ; by Harry
  1736. ;
  1737. _BLTMASKBITMAPRASTPORT
  1738.     movem.l    a1-a6/d7,-(A7)    
  1739.     movem.l    d0-d6,-(A7)
  1740.  
  1741.     ;some tests for the 3 cases
  1742.     move.l    d0,d6
  1743.     and.w    #$f,d6
  1744.     move.l    d2,d7
  1745.     and.w    #$f,d7
  1746.     cmp.l    d6,d7
  1747.     blo.s    .w1
  1748.  
  1749.     add.l    d4,d6
  1750.     add.l    d4,d7
  1751.     subq.l    #1,d6
  1752.     subq.l    #1,d7
  1753.     and.l    #$fffffff0,d6
  1754.     and.l    #$fffffff0,d7
  1755.     cmp.l    d6,d7
  1756.     bls.w    .bl1_1
  1757.  
  1758. .w2    ;case: wrap, amount of words of blitwindow of src < that of dest
  1759.     ;task: blit by 2 steps: all but the last strip, then the last strip
  1760.     move.l    d2,d7
  1761.     add.l    d4,d7
  1762.     and.l    #$f,d7
  1763.     sub.l    d7,d4
  1764.     move.l    6*4(A7),d6
  1765.     bsr.s    .bl1
  1766.     add.l    d4,d0
  1767.     add.l    d4,d2
  1768.     move.l    d7,d4
  1769.     bra.s    .bl2_2
  1770.  
  1771.  
  1772. .w1    ;case: wrap, amount of words of blitwindow of src and of dest equal
  1773.     ;  and (x dest rastport)%16 < (x src bitmap)%16)
  1774.     ;task: blit by 2 steps: all but the last strip, then the last strip
  1775.             ;d6 already (x src)%16
  1776.     move.l    d6,d7
  1777.     add.l    d4,d7
  1778.     cmp.l    #$10,d7
  1779.     blo.s    .w1_last
  1780.     and.l    #$fffffff0,d7
  1781.     sub.l    d6,d7
  1782.     move.l    d7,d4
  1783.     move.l    6*4(A7),d6
  1784.     bsr.s    .bl2
  1785.     move.l    4*4(A7),d4
  1786.     sub.l    d7,d4
  1787.     beq.w    .end
  1788.     add.l    d7,d0
  1789.     add.l    d7,d2
  1790. .w1_last
  1791.     bra.s    .bl2_2
  1792.  
  1793. .bl2    
  1794.     movem.l    a1-a6/d7,-(A7)    
  1795.     movem.l    d0-d6,-(A7)
  1796.  
  1797. .bl2_2    sub.l    a3,a3
  1798.     lea.l    (-2).w,a4
  1799.  
  1800.     ;computing bltawm
  1801.     move.l    d0,d6
  1802.     and.l    #$f,d6
  1803.     moveq.l    #-1,d7
  1804.     lsr.l    d6,d7        ;value for bltafwm in highword
  1805.     move.l    d4,d6
  1806.     add.l    d0,d6
  1807.     neg.l    d6
  1808.     and.l    #$f,d6        ;for bltalwm only the bits which dont fit
  1809.                 ;in the last word are interesting
  1810.     lsl.w    d6,d7        ;value for bltalwm in lowword
  1811.     move.l    d7,-(A7)    ;value for bltawm
  1812.     and.w    d7,(A7)        ;special case: bltafwm is mask for all
  1813.     clr.w    2(A7)        ;  bltalwm is 0 for masking it out
  1814.     add.l    #$10,d4        ;1 word longer blit for taking bltalwm in effect
  1815.     bra.s    .all
  1816.  
  1817. .w3    ;no wrap
  1818. .bl1    movem.l    a1-a6/d7,-(A7)    
  1819.     movem.l    d0-d6,-(A7)
  1820.  
  1821. .bl1_1    ;case: no wrap, amount of words of blitwindow of src and of dest equal
  1822.     sub.l    a3,a3
  1823.     sub.l    a4,a4
  1824.  
  1825.     ;computing bltawm
  1826.     move.l    d0,d6
  1827.     and.l    #$f,d6
  1828.     moveq.l    #-1,d7
  1829.     lsr.l    d6,d7        ;value for bltafwm in highword
  1830.     move.l    d4,d6
  1831.     add.l    d0,d6
  1832.     neg.l    d6
  1833.     and.l    #$f,d6        ;for bltalwm only the bits which dont fit
  1834.                 ;in the last word are interesting
  1835.     lsl.w    d6,d7        ;value for bltalwm in lowword
  1836.     move.l    d7,-(A7)    ;value for bltawm
  1837.  
  1838. .all    ;computing shift
  1839.     move.w    d0,d6
  1840.     move.w    d2,d7
  1841.     and.l    #$f,d6
  1842.     and.l    #$f,d7
  1843.     sub.w    d6,d7
  1844.     and.w    #$f,d7        ;if destination would have neg. shift,
  1845.     swap    D7
  1846.     lsr.l    #4,d7
  1847.     move.l    d7,a5        ;shift in a5, already as BLTCONx
  1848.  
  1849.     ;computing offset in src/mask bitplane
  1850.     moveq.l    #0,d7
  1851.     move.w    bm_BytesPerRow(A0),d7
  1852.     mulu.w    d1,d7        ;bytes in bitplane until start of wanted line
  1853.     add.l    d7,a3
  1854.     move.l    d0,d7
  1855.     lsr.l    #3,d7        ;whole bytes in bpl from start of line until column
  1856.     and.w    #$fffe,d7
  1857.     add.l    d7,a3        ;offset from src bpl until start of blitter
  1858.  
  1859.     ;computing offset in dest bitplane, a4 already set
  1860.     move.l    rp_BitMap(A1),a6    
  1861.     moveq.l    #0,d7
  1862.     move.w    bm_BytesPerRow(A6),d7
  1863.     mulu.w    d3,d7        ;bytes in bpl until start of wanted line
  1864.     add.l    d7,a4
  1865.     move.l    d2,d7
  1866.     lsr.l    #3,d7        ;whole bytes in bpl from start of line until column
  1867.     and.w    #$fffe,d7
  1868.     add.l    d7,a4        ;offset from dest bpl until start of blitter
  1869.  
  1870. .1    ;computing height in lines in BLITSIZE-format
  1871.     lsl.l    #6,d5
  1872.     ;computing width in bytes
  1873.     move.l    d0,d7
  1874.     and.l    #$f,d7
  1875.     add.l    d4,d7
  1876.     add.l    #$f,d7
  1877.     lsr.l    #4,d7
  1878.     move.l    d7,d6
  1879.     and.l    #$3f,d6
  1880.     or.w    d6,d5        ;BLITSIZE
  1881.  
  1882.     ;computing modulo for src/mask bpl, 
  1883.     ;  d7 contains already blitwidth in words
  1884.     add.l    d7,d7
  1885.     moveq.l    #0,d1        ;not needed anymore
  1886.     move.w    bm_BytesPerRow(A0),d1
  1887.     and.w    #$fffe,d1
  1888.     sub.w    d7,d1        ;modulo for src/mask bpl
  1889.  
  1890.     ;computing modulo for dest bpl
  1891.     ;  d7 contains already blitwidth in bytes
  1892.     moveq.l    #0,d3        ;not needed anymore
  1893.     move.w    bm_BytesPerRow(A6),d3
  1894.     and.w    #$fffe,d3
  1895.     sub.w    d7,d3        ;modulo for dest bpl
  1896.  
  1897.     ;evaluate bltbon0
  1898.     move.l    (A7)+,d7
  1899.     move.l    a5,d6
  1900. ;    or.w    6*4+2(A7),d6    ;d6 from stack again (SKIPPED)
  1901.     or.w    #$FCA,d6    ;all channels and minterms
  1902.  
  1903.  
  1904.     ;get # of planes to blit, take minimum of src and dest
  1905.     moveq.l    #0,d4        ;count of planes of src for loop
  1906.     move.b    bm_Depth(A6),d4    ;take lower amount of planes for safety
  1907.     cmp.b    bm_Depth(A0),d4
  1908.     blo.s    .4
  1909.     move.b    bm_Depth(A0),d4
  1910. .4
  1911.  
  1912.     ;set registers which dont change while the whole blit
  1913.     lea.l    $dff000,a6
  1914.     bsr.w    _WaitBlit
  1915.     move.l    d7,$44(A6)    ;bltawm
  1916.     move.w    d1,$62(A6)    ;bltbmod
  1917.     move.w    d1,$64(A6)    ;bltamod
  1918.     move.w    d3,$60(A6)    ;bltcmod
  1919.     move.w    d3,$66(A6)    ;bltdmod
  1920.     move.w    d6,$40(A6)    ;bltcon0
  1921.     move.w    a5,$42(A6)    ;bltcon1
  1922.  
  1923.     ;init loop-counter
  1924.     moveq.l    #0,d7
  1925.     move.b    rp_Mask(A1),d7    ;which planes are to change?
  1926.     moveq.l    #0,d6        ;counter for planes
  1927.  
  1928.     ;here the loop for blitting each plane starts
  1929. .2    lsr.b    #1,d7
  1930.     beq.s    .3        ;skip if bitplane not to change
  1931.  
  1932.     bsr.w    _WaitBlit
  1933.  
  1934.     ;compute startaddress for src
  1935.     move.l    d6,d1
  1936.     lsl.w    #2,d1
  1937.     move.l    bm_Planes(A0,d1.w),a5
  1938.     add.l    a3,a5
  1939.     move.l    a5,$4c(A6)
  1940.  
  1941.     ;compute startaddress for mask
  1942.     lea.l    (a2,a3.l),a5
  1943.     move.l    a5,$50(A6)
  1944.  
  1945.     ;compute startaddress for dest
  1946.     move.l    rp_BitMap(A1),a5
  1947.     move.l    bm_Planes(A5,d1.w),a5
  1948.     add.l    a4,a5
  1949.     move.l    a5,$48(A6)
  1950.     move.l    a5,$54(A6)
  1951.  
  1952.     ;start blit
  1953.     move.w    d5,$58(A6)
  1954.  
  1955. .3    addq.w    #1,d6
  1956.     cmp.b    d4,d6
  1957.     bne.s    .2
  1958. ;    bsr.w    _WaitBlit
  1959. .end    movem.l    (A7)+,d0-d6
  1960.     movem.l    (A7)+,a1-a6/d7
  1961.  
  1962.     rts
  1963.  
  1964. ; Draw
  1965. ; < A1: rastport
  1966. ; < D0: new x
  1967. ; < D1: new y
  1968.  
  1969. _Draw:
  1970.     ; draw the line still to do
  1971.  
  1972.     ; update rastport coordinates
  1973.  
  1974.     move.w    D0,(rp_cp_x,A1)
  1975.     move.w    D1,(rp_cp_y,A1)
  1976.  
  1977.     rts
  1978.  
  1979. ; < A0: cprlist structure
  1980.  
  1981. _FreeCprList:
  1982.     move.l    A6,-(A7)
  1983.     cmp.l    #0,A0
  1984.     beq.b    .end
  1985.     moveq.l    #0,D0
  1986.     move.w    (crl_MaxCount,A0),D0
  1987.     add.l    D0,D0
  1988.     add.l    D0,D0
  1989.     beq.b    .end
  1990.     move.l    (gb_ExecBase,A6),A6
  1991.     move.l    (crl_start,A0),A1
  1992.     cmp.l    #0,A1
  1993.     beq.b    .end
  1994.     JSRLIB    FreeMem    
  1995. .end
  1996.     move.l    (A7)+,A6
  1997.     RTS
  1998.